<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>部门添加</title>
    <link rel="stylesheet" href="/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuimini/css/public.css" media="all">
    <script src="/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <style>
        body { background-color: #ffffff; }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">部门名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" lay-reqtext="部门名称不能为空" autocomplete="off" placeholder="请输入部门名称" value="" class="layui-input">
            <tip>填写部门名称</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部门经理</label>
        <div class="layui-input-inline">
            <select name="dperson" class="layui-input" lay-search>
                <option value="">-请选择-</option>
                <option th:each="e:${emps}" th:value="${e.id}" th:text="${e.empName+'    '+e.empPhone}"></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">经理电话</label>
        <div class="layui-input-block">
            <input type="text" name="dtel" lay-verify="required" autocomplete="off" lay-reqtext="经理电话不能为空" placeholder="请输入经理电话" value="" class="layui-input">
            <tip>填写经理电话</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            if(data.field.dperson == ''){
                layer.alert("请选择部门经理！",{icon:5});
                return false;
            }
            $.post('/department/addDepartment',data.field,function(res){
                if(res.code == '1'){
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                    //通过父页面去重新加载表格
                    parent.layui.table.reload('currentTableId');
                }
                parent.layer.msg(res.msg);
            })
            return false;
        });
    });
</script>
</body>
</html>